from core.api_util import api_util
from utils.response_util import process_response


def send_code(json_data):
    """
    获取短信验证码
    :param json_data:
    :return:
    """
    response = api_util.get_code(json=json_data)
    return process_response(response)


def register_user(code, mobile):
    """
    注册用户
    :param code:
    :param mobile:
    :return:
    """
    json_data = {
        "code": str(code),
        "password": "123456",
        "username": str(mobile)
    }
    response = api_util.register_mobile(json=json_data)
    return process_response(response)


def login(username, password):
    """
    用户登录接口
    :param username:
    :param password:
    :return:
    """
    json_data = {
        "username": username,
        "password": password
    }
    response = api_util.user_login(json=json_data)
    return process_response(response)


def add_shopping_cart(params, headers):
    """
    购物车添加商品
    :param params:
    :return:
    """

    response = api_util.add_shopping(json=params, headers=headers)
    return process_response(response)


def add_message(data, files, headers):
    """
    增加留言
    :param data:
    :param files:
    :param headers:
    :return:
    """

    response = api_util.add_show(data=data, files=files, headers=headers)
    return process_response(response)
